package com.dy.lock.screen.component.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.dy.lock.screen.component.SoftwareVersionComponent;
import com.dy.lock.screen.constants.TransmissionCode;
import com.dy.lock.screen.exception.ServerDisponseException;
import com.dy.lock.screen.pojo.SoftwareVersionInfo;
import com.dy.lock.screen.scoket.Head;
import com.dy.lock.screen.service.SoftwareVersionService;
import com.dy.lock.screen.utils.CommonUtil;
import com.dy.lock.screen.vo.SoftwareVersionVo;
import com.google.gson.Gson;

@Component("softwareVersionComponent")
public class SoftwareVersionComponentImpl implements SoftwareVersionComponent {
	@SuppressWarnings("unused")
	private Gson gson;

	@Resource(name = "softwareVersionService")
	private SoftwareVersionService softwareVersionService;

	public SoftwareVersionComponentImpl() {
		gson = CommonUtil.gson();
	}

	@Override
	public SoftwareVersionVo getSoftwareVersion(String body, Head head) {
		SoftwareVersionInfo versionInfo = this.softwareVersionService
				.getSoftwareVersion();
		if (versionInfo != null) {
			SoftwareVersionVo versionVo = new SoftwareVersionVo();
			versionVo.setVersionName(versionInfo.getUpdateVersion());
			versionVo.setUpdateContent(versionInfo.getUpdateContent());
			versionVo.setVersion(versionInfo.getVersion());
			return versionVo;
		} else {
			throw new ServerDisponseException(
					TransmissionCode.OPERATOR_EXCEPTION.getCode(),
					TransmissionCode.OPERATOR_EXCEPTION.getMessage());
		}
	}

}
